package com.tudulist.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.tudulist.dao.RoleDao;
import com.tudulist.model.Role;

@Repository
public class RoleDaoImpl implements RoleDao {

	private static final long serialVersionUID = 1L;

	@PersistenceContext
	EntityManager em;

	@SuppressWarnings("unchecked")
	public List<Role> findAll() {
		return em.createQuery("from Role").getResultList();
	}

	public Role find(long id) {
		return (Role) em.find(Role.class, id);
	}

	public void save(Role role) {
		em.merge(role);

	}

	public void remove(long id) {
		Role role = (Role) em.find(Role.class, id);
		if (null != role) {
			em.remove(role);
		}

	}

}
